home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / keditcl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.5 KB  |  437 lines

  1. /* This file is part of the KDE libraries
  2.  
  3.    Copyright (C) 1996 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
  4.    Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License as published by the Free Software Foundation; either
  9.    version 2 of the License, or (at your option) any later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.    Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef __KEDITCL_H__
  22. #define __KEDITCL_H__
  23.  
  24. #include <qmultilineedit.h>
  25. #include <qstring.h>
  26. #include <kdialogbase.h>
  27.  
  28. class QDropEvent;
  29. class QPushButton;
  30. class QCheckBox;
  31. class QRadioButton;
  32. class QTextStream;
  33. class KHistoryCombo;
  34. class KIntNumInput;
  35. class QVButtonGroup;
  36.  
  37. class KDEUI_EXPORT KEdGotoLine : public KDialogBase
  38. {
  39.     Q_OBJECT
  40.  
  41. public:
  42.     KEdGotoLine( QWidget *parent=0, const char *name=0, bool modal=true );
  43.     int getLineNumber();
  44.  
  45. public slots:
  46.     void selected( int );
  47.  
  48. private:
  49.     KIntNumInput *lineNum;
  50.  
  51. protected:
  52.     virtual void virtual_hook( int id, void* data );
  53. private:
  54.     class KEdGotoLinePrivate;
  55.     KEdGotoLinePrivate *d;
  56. };
  57.  
  58. ///
  59. class KDEUI_EXPORT KEdFind : public KDialogBase
  60. {
  61.     Q_OBJECT
  62.     Q_PROPERTY( QString text READ getText WRITE setText )
  63.     Q_PROPERTY( bool caseSensitivity READ case_sensitive WRITE setCaseSensitive )
  64.     Q_PROPERTY( bool direction READ get_direction WRITE setDirection )
  65. public:
  66.  
  67.     KEdFind( QWidget *parent = 0, const char *name=0, bool modal=true);
  68.     ~KEdFind();
  69.  
  70.     QString getText() const;
  71.     void setText(QString string);
  72.     void setCaseSensitive( bool b );
  73.     bool case_sensitive() const;
  74.     void setDirection( bool b );
  75.     bool get_direction() const;
  76.  
  77.     /**
  78.      * @returns the combobox containing the history of searches. Can be used
  79.      * to save and restore the history.
  80.      */
  81.     KHistoryCombo *searchCombo() const;
  82.  
  83. protected slots:
  84.     void slotCancel( void );
  85.     void slotUser1( void );
  86.     void textSearchChanged ( const QString & );
  87.  
  88. protected:
  89.   QVButtonGroup* group;
  90.  
  91. private:
  92.     QCheckBox *sensitive;
  93.     QCheckBox *direction;
  94.  
  95.     virtual void done(int i ) { KDialogBase::done(i); }
  96.  
  97. signals:
  98.  
  99.     void search();
  100.     void done();
  101. protected:
  102.     virtual void virtual_hook( int id, void* data );
  103. private:
  104.     class KEdFindPrivate;
  105.     KEdFindPrivate *d;
  106. };
  107.  
  108. ///
  109. class KDEUI_EXPORT KEdReplace : public KDialogBase
  110. {
  111.     Q_OBJECT
  112.  
  113. public:
  114.  
  115.     KEdReplace ( QWidget *parent = 0, const char *name=0, bool modal=true );
  116.     ~KEdReplace();
  117.  
  118.     QString     getText();
  119.     QString     getReplaceText();
  120.     void     setText(QString);
  121.  
  122.     /**
  123.      * @returns the combobox containing the history of searches. Can be used
  124.      * to save and restore the history.
  125.      */
  126.     KHistoryCombo *searchCombo() const;
  127.  
  128.     /**
  129.      * @returns the combobox containing the history of replaces. Can be used
  130.      * to save and restore the history.
  131.      */
  132.     KHistoryCombo *replaceCombo() const;
  133.  
  134.     bool     case_sensitive();
  135.     bool     get_direction();
  136.  
  137. protected slots:
  138.     void slotCancel( void );
  139.     void slotClose( void );
  140.     void slotUser1( void );
  141.     void slotUser2( void );
  142.     void slotUser3( void );
  143.     void textSearchChanged ( const QString & );
  144.  
  145. private:
  146.     QCheckBox     *sensitive;
  147.     QCheckBox     *direction;
  148.  
  149.     virtual void done(int i ) { KDialogBase::done(i); }
  150.  
  151. signals:
  152.     void replace();
  153.     void find();
  154.     void replaceAll();
  155.     void done();
  156. protected:
  157.   virtual void virtual_hook( int id, void* data );
  158. private:
  159.     class KEdReplacePrivate;
  160.     KEdReplacePrivate *d;
  161. };
  162.  
  163.  
  164. /**
  165.  * A simple text editor for the %KDE project.
  166.  * @deprecated Use KTextEditor::Editor or KTextEdit instead.
  167.  *
  168.  * @author Bernd Johannes Wuebben <wuebben@math.cornell.edu>, Waldo Bastian <bastian@kde.org>
  169.  **/
  170.  
  171. class KDEUI_EXPORT_DEPRECATED KEdit : public QMultiLineEdit
  172. {
  173.     Q_OBJECT
  174.  
  175. public:
  176.     /**
  177.      * The usual constructor.
  178.      **/
  179.     KEdit (QWidget *_parent=NULL, const char *name=NULL);
  180.  
  181.     ~KEdit();
  182.  
  183.     /**
  184.      * Search directions.
  185.      * @internal
  186.      **/
  187.     enum { NONE,
  188.        FORWARD,
  189.        BACKWARD };
  190.     /**
  191.      * Insert text from the text stream into the edit widget.
  192.      **/
  193.     void insertText(QTextStream *);
  194.  
  195.     /**
  196.      * Save text from the edit widget to a text stream.
  197.      * If @p softWrap is false soft line wrappings are replaced with line-feeds
  198.      * If @p softWrap is true soft line wrappings are ignored.
  199.      * @since 3.1
  200.      **/
  201.     void saveText(QTextStream *, bool softWrap);
  202.     void saveText(QTextStream *); // KDE 4.0: remove
  203.  
  204.     /**
  205.      *  Let the user select a font and set the font of the textwidget to that
  206.      * selected font.
  207.      **/
  208.     void     selectFont();
  209.  
  210.     /**
  211.      * Present a search dialog to the user
  212.      **/
  213.     void     search();
  214.  
  215.     /**
  216.      * Repeat the last search specified on the search dialog.
  217.      *
  218.      *  If the user hasn't searched for anything until now, this method
  219.      *   will simply return without doing anything.
  220.      *
  221.      * @return @p true if a search was done. @p false if no search was done.
  222.      **/
  223.     bool     repeatSearch();
  224.  
  225.     /**
  226.      * Present a Search and Replace Dialog to the user.
  227.      **/
  228.     void     replace();
  229.  
  230.     /**
  231.      * Present a "Goto Line" dialog to the user.
  232.      */
  233.     void     doGotoLine();
  234.  
  235.     /**
  236.      * Clean up redundant whitespace from selected text.
  237.      */
  238.     void        cleanWhiteSpace();
  239.  
  240.     /**
  241.      * Install a context menu for KEdit.
  242.      *
  243.      *  The Popup Menu will be activated on a right mouse button press event.
  244.      */
  245.     void     installRBPopup( QPopupMenu* );
  246.  
  247.     /**
  248.      * Retrieve the current line number.
  249.      *
  250.      * The current line is the line the cursor is on.
  251.      **/
  252.     int     currentLine();
  253.  
  254.     /**
  255.      * Retrieve the actual column number the cursor is on.
  256.      *
  257.      *  This call differs
  258.      *    from QMultiLineEdit::getCursorPosition() in that it returns the actual cursor
  259.      *    position and not the character position. Use currentLine() and currentColumn()
  260.      *    if you want to display the current line or column in the status bar for
  261.      *    example.
  262.      */
  263.     int     currentColumn();
  264.  
  265.  
  266.     /**
  267.      * Start spellchecking mode.
  268.      */
  269.     void spellcheck_start();
  270.  
  271.     /**
  272.      * Exit spellchecking mode.
  273.      */
  274.     void spellcheck_stop();
  275.  
  276.     /**
  277.      * Allow the user to toggle between insert mode and overwrite mode with
  278.      * the "Insert" key. See also toggle_overwrite_signal();
  279.      *
  280.      * The default is false: the user can not toggle.
  281.      */
  282.     void setOverwriteEnabled(bool b);
  283.  
  284.     QString selectWordUnderCursor();
  285.  
  286.     /// @since 3.3
  287.     QPopupMenu *createPopupMenu( const QPoint& pos );
  288.  
  289.     void setAutoUpdate(bool b);
  290.  
  291. signals:
  292.     /** This signal is emitted if the user dropped a URL over the text editor
  293.       * QMultiLineEdit widget.
  294.       *
  295.       *  Note that the user can drop also Text on it, but
  296.       * this is already handled internally by QMultiLineEdit.
  297.       */
  298.     void        gotUrlDrop(QDropEvent* e);
  299.  
  300.     /** This signal is emitted whenever the cursor position changes.
  301.      *
  302.      * Use this in conjunction with currentLine(), currentColumn()
  303.      * if you need to know the cursor position.
  304.      */
  305.     void     CursorPositionChanged();
  306.  
  307.     /**
  308.      * This signal is emitted if the user toggles from insert to overwrite mode
  309.      * or vice versa.
  310.      *
  311.      * The user can do so by pressing the "Insert" button on a PC keyboard.
  312.      *
  313.      * This feature must be activated by calling setOverwriteEnabled(true)
  314.      * first.
  315.      */
  316.     void     toggle_overwrite_signal();
  317.  
  318. public slots:
  319.       /**
  320.        * @internal
  321.        **/
  322.     void corrected (const QString &originalword, const QString &newword, unsigned int pos);
  323.       /**
  324.        * @internal
  325.        **/
  326.     void misspelling (const QString &word, const QStringList &, unsigned int pos);
  327. private slots:
  328.  
  329.       /**
  330.        * @internal
  331.        * Called from search dialog.
  332.        **/
  333.     void search_slot();
  334.  
  335.       /**
  336.        * @internal
  337.        **/
  338.     void searchdone_slot();
  339.  
  340.       /**
  341.        * @internal
  342.        **/
  343.     void replace_slot();
  344.  
  345.       /**
  346.        * @internal
  347.        **/
  348.     void replace_all_slot();
  349.  
  350.       /**
  351.        * @internal
  352.        **/
  353.     void replace_search_slot();
  354.  
  355.       /**
  356.        * @internal
  357.        **/
  358.     void replacedone_slot();
  359.  
  360.       /**
  361.        * Cursor moved...
  362.        */
  363.     void slotCursorPositionChanged();
  364.  
  365. protected:
  366.     void computePosition();
  367.     int     doSearch(QString s_pattern, bool case_sensitive,
  368.              bool regex, bool forward,int line, int col);
  369.  
  370.     int     doReplace(QString s_pattern, bool case_sensitive,
  371.               bool regex, bool forward,int line, int col,bool replace);
  372.  
  373.       /**
  374.        * Sets line and col to the position pos, considering word wrap.
  375.        **/
  376.     void    posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col);
  377.  
  378.     /**
  379.      * Reimplemented for internal reasons, the API is not affected.
  380.      */
  381.     virtual void create( WId = 0, bool initializeWindow = true,
  382.                          bool destroyOldWindow = true );
  383.  
  384.     /**
  385.      * Reimplemented for internal reasons, the API is not affected.
  386.      */
  387.     virtual void ensureCursorVisible();
  388.     virtual void setCursor( const QCursor & );
  389.     virtual void viewportPaintEvent( QPaintEvent* );
  390.  
  391. protected:
  392.  
  393.     void     keyPressEvent      ( QKeyEvent *  );
  394.  
  395.     // DnD interface
  396.     void        dragMoveEvent(QDragMoveEvent* e);
  397.     void        dragEnterEvent(QDragEnterEvent* e);
  398.     void        dropEvent(QDropEvent* e);
  399.     void        contentsDragMoveEvent(QDragMoveEvent* e);
  400.     void        contentsDragEnterEvent(QDragEnterEvent* e);
  401.     void        contentsDropEvent(QDropEvent* e);
  402.  
  403. private:
  404.     QTimer* repaintTimer;
  405.  
  406.     QString    killbufferstring;
  407.     QWidget     *parent;
  408.     KEdFind     *srchdialog;
  409.     KEdReplace     *replace_dialog;
  410.     KEdGotoLine *gotodialog;
  411.  
  412.     QString     pattern;
  413.  
  414.     bool     can_replace;
  415.     bool    killing;
  416.     bool     killtrue;
  417.     bool     lastwasanewline;
  418.     bool        saved_readonlystate;
  419.     int     last_search;
  420.     int     last_replace;
  421.     int     replace_all_line;
  422.     int     replace_all_col;
  423.  
  424.     int     line_pos, col_pos;
  425.     bool        fill_column_is_set;
  426.     bool        word_wrap_is_set;
  427.     int         fill_column_value;
  428.  
  429. protected:
  430.     virtual void virtual_hook( int id, void* data );
  431. private:
  432.     class KEditPrivate;
  433.     KEditPrivate *d;
  434. };
  435.  
  436. #endif
  437.